package com.bjpowernode.crm.web.controller;

import com.bjpowernode.crm.constants.Constants;
import com.bjpowernode.crm.pojo.Dept;
import com.bjpowernode.crm.service.DeptService;
import com.bjpowernode.crm.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController // @Controller+@ResponseBody
@RequestMapping("dept")
public class DeptController {

    @Autowired
    private DeptService deptService;

    @GetMapping("depts.json")
    public List getAll() {
        return deptService.getAll();
    }

    @PostMapping("save.do")
    public Map save(Dept dept) {
        dept.setId(UUIDUtils.getUUID());
        deptService.save(dept);

        return Constants.Result.SUC_WITH_MSG;
    }

    @GetMapping("dept.json")
    public Dept get(String id) {
        return deptService.get(id);
    }

    @PutMapping("edit.do")
    public Map edit(Dept dept) {

        deptService.edit(dept);

        return Constants.Result.SUC_WITH_MSG;
    }

    @DeleteMapping("del.do")
    public Map del(String[] ids) {

        deptService.del(ids);

        return Constants.Result.SUC_WITH_MSG;
    }
}
